/**
 * 版权所有 (TMS)
 */
package com.xiweicheng.test.redisson;

import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author xiweicheng
 * @date 2021/5/29 4:26 下午
 */
@Slf4j
@RestController
public class RedisController {

    //    @Autowired
    @Resource
    RedisTemplate<String, Object> redisTemplate;

    @GetMapping("redis/set/{id}")
    public Object set(@PathVariable("key") Long id) {
        Long cnt = redisTemplate.opsForList().leftPush("list01", Data.builder().id(id).name("test" + id).build());
        return cnt;
    }

    @GetMapping("redis/get/{id}")
    public Object get(@PathVariable("key") Long id) {
        Object val = redisTemplate.opsForList().index("list01", 0);
        log.info("{}", val instanceof Data);
        return val;
    }
}
